/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_question.cpp

	$Header: /heroes4/script_question.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "script_question.h"

#include "adventure_map.h"
#include "adventure_map_window.h"
#include "simple_dialog.h"
#include "streambuf_operators.h"

// --------------------------------------------------------------------------
// t_script_question members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_question::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	return		read_string16( stream, m_text )
			&&	t_script_branch_action::read_from_map( stream, format_version );
}

bool t_script_question::read( std::streambuf& stream, int version)
{
	if (!t_script_branch_action::read( stream, version ))
		return false;
	
	return read_string16( stream, m_text );
}

bool t_script_question::write( std::streambuf& stream ) const
{
	if (!t_script_branch_action::write( stream ))
		return false;
	
	return write_string16( stream, m_text );
}

void t_script_question::execute(t_script_context_hero const& context) const
{
	if (yes_no_dialog(get_text()))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_question::execute(t_script_context_town const& context) const
{
	if (yes_no_dialog(get_text()))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_question::execute(t_script_context_object const& context) const
{
	if (yes_no_dialog(get_text()))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_question::execute(t_script_context_army const& context) const
{
	if (yes_no_dialog(get_text()))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);

	context.map->get_map_window()->halt_movement();
}

void t_script_question::execute(t_script_context_global const& context) const
{
	if (yes_no_dialog(get_text()))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

